<ion-view view-title="采购单详情" show-tabs>
	<ion-content>
		<ion-list class="wrap-light2">
			<ion-item>
			    <span class="list-label text-right">单号</span>
			    <span>{{detail.order_no}}</span>
			</ion-item>

			<ion-item class="">
			    <span class="list-label text-right">发生时间</span>
			    <time>{{detail.date | date: "yyyy-MM-dd HH:mm:ss"}}</time>
			</ion-item>

			<ion-item class="item-icon-right" ng-if="detail.warehouse" href="#/department-{{detail.warehouse._id}}">
			    <span class="list-label text-right">入库仓库</span>
			    <span>{{detail.warehouse.name}}</span>
	     		<i class="icon ion-ios-arrow-right"></i>
			    
			</ion-item>

			<ion-item class="item item-icon-right" href="#/supplier-{{detail.supplier._id}}">
			    <span class="list-label text-right">供应商</span>
			    <span>{{detail.supplier.company}}</span>
	     		<i class="icon ion-ios-arrow-right"></i>
			</ion-item>
			<ion-item class="item-base item-button-right state-history" ng-class="{'item-borderless':!$first,'state-current':$first,'last':$last,'state-history-expend':isExpend}" ng-repeat="sh in detail.state_history | orderBy: '-operation.state'" ng-if="isExpend || $first">

				<div class="row row-nopadding">
					<span class="list-label text-right"><span ng-if="$first">状态</span></span>
					<span class="state {{stateUi[sh.operation.state].bg}}">
						<i class="icon state-icon {{stateUi[sh.operation.state].icon}} {{stateUi[sh.operation.state].color}}"></i>
					</span>
					<div class="col">
					    <span class="{{stateUi[sh.operation.state].color}}">{{sh.operation.note}}</span>
					    
					    <span class="item-note">{{sh.operator.name}}</span>
						
					     <p ng-show="isExpend" class="padding-top">
							<span class="meta">{{sh.date | date:'yyyy-MM-dd HH:mm:ss'}}</span>
						</p>
					</div>
				</div>
			   
				<button class="button button-col button-light" ng-if="$first" ng-click="toggleHistory()">历史
					<i class="icon-right" ng-class="{'ion-ios-arrow-down': !isExpend,'ion-ios-arrow-up': isExpend}"></i>
				</button>
			</ion-item>
			<ion-item ng-click="updateState()" class="royal text-center" ng-if="isExpend && lastState!==0&& lastState!==4 && lastState!==5"><i class="icon ion-ios-loop icon-left"></i>更新状态</ion-item>
			
			
			<ion-item class="item item-divider margin-top-large">
			    采购清单
			</ion-item>

			<ion-item class="product-property" ng-repeat="product in detail.list" ng-class="{on: isItemShown(product)}" ng-click="toggleProperty(product)">
				<h2>{{product.properties.brand.value + product.properties.model.value}}<i class="pull-right" ng-class="{'ion-ios-arrow-down': !isItemShown(product),'ion-ios-arrow-up': isItemShown(product)}"></i></h2>
				<div class="meta margin-top-small">
					<span ng-if="product.cost_price">单价：{{product.cost_price | currency:'￥'}}</span>
					<span>数量：{{product.count}}部</span>
					<span class="pull-right nomargin dark" ng-if="product.cost_price">小计：{{product.cost_price*product.count | currency:'￥'}}</span>
				</div>
				<div class="prop-list item-accordion" ng-if="isItemShown(product)">
					<p ng-repeat="property in product.properties" class="prop-item" ng-if="property.name!='品牌' && property.name!='型号'">
						<span class="prop-label">{{property.name}}:</span>
						<span class="prop-value">{{property.value}}</span>
					</p>
				</div>
			</ion-item>

			<ion-item class="padding" ng-if="detail.total_cost">
			    <div class="row row-center">
					<div>总计：</div>
					<div class="col text-right">{{detail.total_cost | currency:'￥'}}</div>
				</div>
			    <div class="row row-center" ng-if="detail.total_cost!=detail.paid">
					<div>待付：</div>
					<div class="col assertive text-right">{{detail.total_cost-detail.paid | currency:'￥'}}</div>
				</div>
			</ion-item>
		</ion-list>
    </ion-content>
</ion-view>
